<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>添加提问问题</title>
<link href="${base}/resources/admin/css/amazeui.css" rel="stylesheet" type="text/css" />
<link href="${base}/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .text-line {
            line-height: 20px;
        }
    </style>
</head>
<body>
	<div class="path">
		<a href="${base}/asl-admin/common/index.htm">${message("admin.path.index")}</a> &raquo; 添加提问问题
	</div>
	<form id="inputForm"  class="am-tabs" data-am-tabs="{noSwipe: 1}" action="save.htm"  method="post" enctype="multipart/form-data">
        <ul class="tab am-tabs-nav am-nav am-nav-tabs">
            <li class="am-active"><a href="javascript: void(0)">基本信息</a></li>
            <li><a href="javascript: void(0)">问题图片</a></li>
        </ul>
        <div class="am-tabs-bd">
		<table class="input tabContent am-tab-panel am-active">
            <tr>
                <th>
                    <span class="requiredField">*</span>提问者:
                </th>
                <td>
                    <select name="memberId" data-am-selected="{searchBox: 1}">
                    [#list members as m ]
                        <option value="${m.id}" >${m.username}[#if m.name]（${m.name}）[/#if]</option>
                    [/#list]
                    </select>
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>被提问老师:
                </th>
                <td>
                    <select name="teacherId" id="teacherId" data-am-selected="{searchBox: 1}">
                    [#list members as m ]
                        [#if m.type="teacher"]
                            <option value="${m.id}" >${m.username}[#if m.name]（${m.name}）[/#if]</option>
                        [/#if]
                    [/#list]
                    </select>
                </td>
            </tr>
			<tr>
				<th>
					<span class="requiredField">*</span>问题标签:
				</th>
				<td>
					<label><input type="radio" name="payType" value="风水" />风水 </label>
                    <label><input type="radio" name="payType" value="婚恋感情" />婚恋感情 </label>
                    <label><input type="radio" name="payType" value="事业财运" />事业财运 </label>
                    <label><input type="radio" name="payType" value="其他" />其他 </label>
				</td>
			</tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>提问价格:
                </th>
                <td>
                    <input type="text" name="payPrice" class="text" maxlength="200" />
                </td>
            </tr>
            <tr>
                <th>
                    是否分享:
                </th>
                <td>
                    <label><input type="radio" name="isShare" value="true" />是</label>
                    <label><input type="radio" name="isShare" value="false" />否</label>
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>姓名:
                </th>
                <td>
                    <input type="text" name="name" class="text" maxlength="200" />
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>性别:
                </th>
                <td>
                    <label><input type="radio" name="gender" value="male" />男</label>
                    <label><input type="radio" name="gender" value="female" />女</label>
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>出生日期:
                </th>
                <td>
                    <input type="text" id="birth" name="birth" class="text Wdate" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'});" />
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>出生时辰:
                </th>
                <td>
                    <input type="text" name="birthHour" class="text" maxlength="200" />
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>标题:
                </th>
                <td>
                    <input type="text" name="title" class="text" maxlength="800" style="width: 500px" />
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>内容:
                </th>
                <td>
                    <textarea name="content" class="text text-line" style="width: 400px;height: 200px"></textarea>
                </td>
            </tr>
            <tr>
                <th>
                    <span class="requiredField">*</span>邮箱:
                </th>
                <td>
                    <input type="text" name="email" class="text" maxlength="200" />
                </td>
            </tr>
		</table>
        <table id="questionImageTable" class="input tabContent am-tab-panel">
            <tr>
                <td colspan="4">
                    <a href="javascript:;" id="addQuestionImage"
                       class="button">${message("admin.product.addProductImage")}</a>
                </td>
            </tr>
            <tr class="title">
                <td>
                ${message("ProductImage.file")}
                </td>
                <th>
                    预览
                </th>
                <td>
                ${message("admin.common.delete")}
                </td>
            </tr>
		</table>
        </div>
		<table class="input">
            <tr>
                <th>
                    &nbsp;
                </th>
                <td>
                    <input type="submit" class="button" value="${message("admin.common.submit")}" />
                    <input type="button" class="button" value="${message("admin.common.back")}" onclick="location.href='list.htm'" />
                </td>
            </tr>
		</table>
	</form>
</body>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.tools.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/resources/admin/editor/kindeditor.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/common.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/input.js"></script>
<script type="text/javascript" src="${base}/resources/admin/datePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/amazeui.min.js"></script>
<script type="text/javascript">
    $().ready(function() {

        var $inputForm = $("#inputForm");
        var $browserButton = $("#browserButton");


        var $questionImageTable = $("#questionImageTable");
        var $addQuestionImage = $("#addQuestionImage");
        var $deleteProductImage = $("a.deleteProductImage");
        var questionImageIndex = 0;

        var $payType = $("input[name = 'payType']");

        var $teacherId = $("#teacherId");

        $payType.on("click", function() {
            var teacherId = $teacherId.find("option:selected").val();
            var payType = $(this).val();
            var type;
            if ($.trim(payType) == "风水") {
                type = 1;
            } else if ($.trim(payType) == "婚恋感情") {
                type = 2;
            } else if ($.trim(payType) == "事业财运") {
                type = 3;
            } else if ($.trim(payType) == "其他") {
                type = 4;
            }
            $.ajax({
                url:"/asl-admin/question/opposite.htm",
                type:"POST",
                data: {type:type, teacherId:teacherId},
                dataType:"json",
                success : function (data) {
                    var price = data.data;
                    $("input[name='payPrice']").val(price);
                }
            })
        })


    [@flash_message /]

        $browserButton.browser();

        // 表单验证
        $inputForm.validate({
            rules: {
                payType: "required",
                payPrice: {
                    required: true,
                    digits: true
                },
                isShare: "required",
                name:"required",
                gender: "required",
                birth:"required",
                birthHour:"required",
                title:"required",
                email: {
                    required: true,
                    email: true
                },
                memberId:"required",
                teacherId:"required",
                content:"required"
            }
        });


        // 增加认证图片
        $addQuestionImage.click(function () {
        [@compress single_line = true]
            var trHtml =
                    '<tr>
                    <td>
                    <input type="file" name="questionImage" class="productImageFile imgChange"\/>
        <\/td>
        <td>
        <div class="photoChange"><\/div>
        <\/td>
        <td>
        <a href="javascript:;" class="deleteProductImage"><i class="iconfont icon-shequshanchu del-icon"><\/i><\/a>
        <\/td>
        <\/tr>';
        [/@compress]
            $questionImageTable.append(trHtml);
            questionImageIndex++;

            $('.imgChange').change(function () {
                var file = this.files[0];
                var r = new FileReader();
                var t = $(this);
                r.readAsDataURL(file);
                $(r).load(function () {
                    t.parent().next().children('.photoChange').html('<img src="' + this.result + '" alt=""  />');
                })
            });
        });


        // 删除商品图片
        $deleteProductImage.live("click", function () {
            var $this = $(this);
            $.dialog({
                type: "warn",
                content: "${message("admin.dialog.deleteConfirm")}",
                onOk: function () {
                    $this.closest("tr").remove();
                }
            }, 260, 180);
        });


    });
</script>
</html>
